package Demo;

import java.util.ArrayList;
import java.util.Random;

public class ThreadDemo6 {
    public static long count1 = 0;
    public static long count2 = 0;
    public static void main(String[] args) throws InterruptedException {
        long c = System.currentTimeMillis();
        ArrayList<Integer> arr =new ArrayList<>(1000_0000);
        for(int i = 0 ; i < 1000_0000 ; i ++){
            Random random = new Random();
            arr.add(random.nextInt() % 10);
        }
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 1000_0000 ; i = i + 2){
                    count1 = count1 + arr.get(i);
                }

        });
        Thread t2 = new Thread(()->{
            for (int i = 1; i < 1000_0000; i = i + 2) {
                    count2 = count2 + arr.get(i);
                }
        });
        long a = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long b = System.currentTimeMillis();
        System.out.println(b - a);
        long flag = 0;

        for (int i = 0; i < 1000_0000; i++) {
            flag = flag + arr.get(i);
        }
        long d = System.currentTimeMillis();
        System.out.println(d - a);
    }
}
